package com.kclmedu.springsecuritydb.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

/**
* @ProjectName:
* @Package:        com.kclmedu.springsecuritynodb.controller
* @ClassName:      AdminController
* @Description:    控制器
* @Author:         Teacher.YE
* @CreateDate:     2019/7/11 22:12
* @Version:        1.0.0
*/
@Slf4j
@RestController
@RequestMapping(value = "admin")
public class AdminController {

    /**
    * @Description:    通过@AuthenticationPrincipal 注解来注入 Principal 对象，我们就可以直接
     * 使用这个对象来获取认证的信息
    * @Author:         Teacher.YE
    * @CreateDate:     2019/7/11 22:43
    * @Version:        1.0.0
    */
    @RequestMapping(value = "main")
    public String mainList(@AuthenticationPrincipal Principal principal) {
        log.debug("---> 请求进入mainList方法...");
        log.info("注入进来的principal对象是："+principal);
        //获取认证的用户名
        String currentUser = principal.getName();
        return "Welcome to admin page, 欢迎: "+currentUser+" 的来到";
    }

    @RequestMapping(value = "add")
    public String addMethod() {
        log.info("===> 请求进入 addMethod方法中...");
        //
        return "欢迎进入管理后台的添加数据页面";
    }
}
